import { defineStore } from 'pinia'

export const useChildrenStore = defineStore('children', {
  state: () => ({
    items: [] as Array<{ id: number; name: string }>,
    currentChildId: null as number | null,
  }),
  actions: {
    async load() {
      const { children } = await $fetch('/api/children')
      this.items = children
      if (!this.currentChildId && children.length) this.currentChildId = children[0].id
    },
    setCurrent(id: number) {
      this.currentChildId = id
    }
  }
})


